﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Arcanea.StateEditor.FormOption;
using Arcanea.StateEditor.XmlObjects;
using Arcanea.Mediator.Toolbox;
using Arcanea.Mediator.XmlClasses;

namespace Arcanea.StateEditor
{
    public partial class LinkRepresentation : UserControl
    {
        private LinkRepresentationXml modele = new LinkRepresentationXml();
        public LinkRepresentationXml Modele
        {
            get
            {
                return modele;
            }
            set
            {
                modele = value;
                if (modele == null)
                {
                    return;
                }
                if (modele.IsClientDeclenche)
                {
                    labelTypePaquet.Text = "Send by the client";
                    labelTypePaquet.ForeColor = Color.Blue;
                    labelDeclenchement.ForeColor = Color.Blue;
                }
                else
                {
                    labelTypePaquet.Text = "Send by the server";
                    labelTypePaquet.ForeColor = Color.Red;
                    labelDeclenchement.ForeColor = Color.Red;
                }

                labelDeclenchement.Text = "Raise on :";

                foreach (string  s in modele.AllPacketAdmited)
                {
                    labelDeclenchement.Text += " " + s;
                }
            }
        }

        private string xmlFilePathPacket = null;

        public void GenerateGuid()
        {
            modele.GUID = this.GetHashCode();
        }

        public LinkRepresentation()
        {
            InitializeComponent();
        }

        public LinkRepresentation(string XMLFilePathPacket)
            : this()
        {
            this.xmlFilePathPacket = XMLFilePathPacket;
        }

        private void Action_DoubleClick(object sender, EventArgs e)
        {
            IList<XmlPacket> AllXmlPackets = XMLToolbox.XmlListPacketLoading(xmlFilePathPacket);

            FormOptionLinkRepresentation fmr = new FormOptionLinkRepresentation();
            fmr.Modele = this.Modele;
            fmr.AllXmlPacket = AllXmlPackets;
            DialogResult dr = fmr.ShowDialog();

            if (dr == DialogResult.OK)
            {
                this.Modele = fmr.Modele;
                this.Parent.Refresh();
            }
        }

        private void buttonSuppress_Click(object sender, EventArgs e)
        {
            modele = null;
            this.Parent.Refresh();
        }
    }
}
